import Vue from 'vue'
import Router from 'vue-router'
import store from '../store'
// import _ from 'lodash'
// import HelloWorld from '@/components/HelloWorld'
import index from '@/views/index'
import unload from '@/views/unLoad'
import login from '@/views/customUser/login'
import checkUnload from '@/views/checkUnload'
import viewDetail from '@/views/viewDetail/viewDetail'
import errorSubmit from '@/views/errorPage/errorSubmit'

Vue.use(Router)
let thisRouter = new Router({
  routes: [
    {
      path: '/',
      name: 'index',
      component: index,
      meta: { activeMenu: 'index', title: '智慧场站' }
    },
    {
      path: '/unload',
      name: 'unload',
      icon: 'stats-bars',
      component: unload,
      meta: { activeMenu: 'unload', title: '到站卸车' }
    },
    {
      path: '/checkUnload',
      name: 'checkUnload',
      icon: 'stats-bars',
      component: checkUnload,
      meta: { activeMenu: 'checkUnload', title: '到站卸车-核对' }
    },
    {
      path: '/viewDetail',
      name: 'viewDetail',
      icon: 'stats-bars',
      component: viewDetail,
      props: (route) => {
        return route.query
      },
      meta: { activeMenu: 'viewDetail', title: '查看详情' }
    },
    {
      path: '/errorSubmit',
      name: 'errorSubmit',
      icon: 'stats-bars',
      component: errorSubmit,
      props: (route) => {
        return route.query
      },
      meta: { activeMenu: 'errorSubmit', title: '错误提交' }
    },
    {
      path: '/login',
      name: 'login',
      icon: 'stats-bars',
      component: login,
      meta: { activeMenu: 'login', title: '登录' }
    }
  ]
})
// 前置守卫
thisRouter.beforeEach((to, from, next) => {
  let activeMenu = { name: to.meta.activeMenu, title: to.meta.title }
  if (!activeMenu) {
    console.error('此路由没有acriveMenu')
  } else {
    store.dispatch('setActiveMenu', activeMenu)
  }
  next()
  // let power = _.find(store.state.currentUser.permission, { 'name': String(to.name), 'type': '2' })
  // if (power) {
  //   next()
  // } else {
  //   Vue.prototype.$Message.info('无权限访问，请联系管理员调整权限')
  //   // next('/')
  // }
})
// 路由跳转后scroll 位置
thisRouter.afterEach((to, from, next) => {
  window.scrollTo(0, 0)
})

export default thisRouter
